package org.jks.service;

import java.util.List;

import org.jks.model.AttachmentType;
import org.springframework.stereotype.Service;

@Service
public class AttachmentTypeService extends EntityService<AttachmentType>{
	
	public AttachmentTypeService(){
		MODEL_NAME = AttachmentType.class.getSimpleName();
		CLASS_NAME = AttachmentType.class;
	}
	
	public List<AttachmentType> listByGroup(long attachmentGroupId){
		String hql = "from " + MODEL_NAME + " where AttachmentGroup.Id='" + attachmentGroupId + "'";
		List<AttachmentType> attachmentTypes = super.find(hql);
		return attachmentTypes;
	}
	
	public AttachmentType findByName(String name){
		String hql = "from " + MODEL_NAME + " where Name='" + name + "'";
		List<AttachmentType> attachmentTypes = super.find(hql);
		if(attachmentTypes != null && attachmentTypes.size() > 0){
			return attachmentTypes.get(0);
		}
		return null;
	}
	
	public List<AttachmentType> listAllByDesc(String desc)
	{
		String hql = "from " + MODEL_NAME + " where Desp='" + desc + "'";
		List<AttachmentType> temp = super.find(hql);
		if(temp == null || temp.size() == 0)
		{
			return null;
		}
		return temp;
	}
}
